
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/statics/layui/layui.js" charset="UTF-8"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/layui/css/layui.css"/>
</head>

<style>
    #form{
        border-radius: 10px;
        padding-left: 20px;
    }
</style>
<body>
<br><br>
<div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">账号：</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="loginName" id="loginName" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">姓名：</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="userName" id="userName" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-warm" lay-event="add">新增</button>
    </div>
</script>
<table class="layui-hide" id="test"  lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="view">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use(['table','form','jquery'], function(){
        var table = layui.table;
        var form=layui.form;
        var $=layui.jquery;

        var tableIns=table.render({
            elem: '#test'
            ,url:'${pageContext.request.contextPath}/tSysUser/list'
            ,toolbar:'#toolbarDemo'
            ,cols: [[
                {field: 'userId', width: 80, title: '用户ID'}
                , {field: 'deptId', width: 180, title: '部门ID'}
                , {field: 'loginName', width: 100, title: '登录账号'}
                , {field: 'sex', width: 100, title: '性别',templet:function (data){
                        if (data.sex==="1"){
                            return "女"
                        }else{
                            return "男"
                        }
                    }}
                , {field: 'userName', width: 130, title: '用户昵称'}
                , {field: 'userType', width: 271, title: '用户类型（00系统用户 01注册用户）',}
                , {field: 'email', width: 200, title: '邮箱'}
                , {field: 'phonenumber', width: 180, title: '电话'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 263}
            ]]
            ,page: true
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            console.log(data.field)
            //这里以搜索为例
            tableIns.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    loginName: data.field.loginName
                    ,username: data.field.username
                    //…
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });
        // 工具栏事件
        table.on('toolbar(test)', function(obj){
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var othis = lay(this);
            switch(obj.event){
                case 'add':
                    location.href="${pageContext.request.contextPath}/tSysUser/toUserAdd";
                    break;
            };
        });

        //触发单元格工具事件
        table.on('tool(test)', function(obj){ // 双击 toolDouble
            var data = obj.data;
            if(obj.event === 'view'){
                layer.open({
                    type:2,
                    title:"",
                    area:["80%", "80%"],
                    content:["${pageContext.request.contextPath}/tSysUser/view/"+data.userId]
                })
            }else if(obj.event === 'del'){
                layer.confirm("真的删除行吗",function (index){
                    $.get('${pageContext.request.contextPath}/tSysUser/delete/'+data.userId,function (data) {
                        layer.close(index);
                        if (data==='1'){
                            location.reload();
                        }else {
                            alert("删除失败");
                        }
                    })
                })
            }
            else if(obj.event==='edit'){
                location.href="${pageContext.request.contextPath}/tSysUser/toEdit/"+data.userId;
            }
        });
    });


</script>
</body>
</html>